因為今天是中秋節,所以要跳脫框架來作一個中秋月兔賀卡(就是任性),其實是課程中一個可愛的小活動,讓大家可以運用程式碼畫出賀卡,先分享一下最終完成圖
活動其實是希望我們以for迴圈為主來完成賀卡圖,但當時我選擇運用陣列及函式來挑戰完成(我絕不承認是因為懶惰),今天想分享一下製作時的想法:
ps. 我發現表情符號裡面的月亮好像顯示不出來,所以程式碼內就先摘掉了XD"
let newLine = ''
function drawRabbit(line) {
newLine = ''
for (let i = 0; i < line.length; i++) {
if (line[i] === 1) {
newLine += '⬜'
} else if (line[i] === 2) {
newLine += '⬛'
} else if (line[i] === 3) {
newLine += '?'
} else {
newLine += ' '
}
}
return newLine
}
console.log(drawRabbit([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 1, 0, 1, 3, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 1, 0, 1, 3, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 1, 0, 1, 3, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 1, 0, 1, 3, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1]))
console.log(drawRabbit([0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]))
console.log(' ~ 祝大家中秋節快樂 ~')
以上步驟成功完成中秋月兔賀卡!
新手第一次嘗試發自己完成的程式碼,可能有很多地方寫得不是那麼好,
還請各位多多指教並祝大家中秋節快樂!再忙都要記得吃烤肉跟月餅哦❤️